from django.db import models

# Create your models here.
# 商品类
from utils.models import BaseModel


class Product(BaseModel):
    product_id = models.AutoField(primary_key=True)
    product_name = models.CharField(max_length=20)
    description = models.CharField(max_length=30, default='暂无该商品描述信息')
    img_url = models.CharField(max_length=255)
    price = models.DecimalField(max_digits=5, decimal_places=2)
    type = models.ForeignKey('Category.GoodsCategory', null=True, blank=True, on_delete=models.SET_NULL)
    num = models.IntegerField(null=True, default=100)
    sales = models.IntegerField(null=True, default=0)
    # 外键的级联操作，若外键对应的那条数据被删除了，那么这条数据也会被删除
    merchant = models.ForeignKey('Merchants.Merchant', on_delete=models.CASCADE)
    is_delete= models.BooleanField(default=False)

    class Meta:
        managed = True
        db_table = 'product'
